<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--   获取绝对路径 -->
<c:set var="ctx" value="${pageContext.request.contextPath }" />
<c:set var="m" value="${requestScope.menu }" />
<%@ include file="/common/include/include.jsp"%>
</head>
<body>

	<div id="content-container">
		<%@ include file="/common/include/pageTitleBread.jsp"%>
	<div id="page-content">
			<div class="col-lg-12">
		        <div class="panel">
		            <div class="panel-heading">
		                <h3 class="panel-title">${requestScope.nowBread }</h3>
		            </div>
		            <form id="editForm" class="panel-body form-horizontal form-padding">
		            
						<input type="hidden" id ="parentId" name="parentId"  value="${m!=null?m.parentId:'0' }">
						<input type="hidden" id = "id" name="id" value="${m!=null?m.id:'' }">		            
		            	<input type="hidden" id = "opreate" name="opreate" value="${requestScope.nowBread }">
		            	<input type="hidden" id = "isparent" name="isparent" value="${m!=null?m.isparent:'' }">
		            
		            	<div class="form-group">
		                    <label class="col-md-3 control-label" for="demo-text-input">父级菜单</label>
		                    <div class="col-md-5">
		                        <div class="input-group mar-btm">
			                        <input type="text" id="parent_name" value="${m!=null?m.parent_name:'根目录' }" readonly class="form-control">

			                        
			                        <span class="input-group-btn">
			                            <button class="btn btn-mint" type="button" onclick="selectOneMenu()">选择</button>
			                        </span>
			                    </div>
		                        <small class="help-block">请选择</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label" for="demo-text-input">名称</label>
		                    <div class="col-md-9">
		                        <input type="text"  name="name" class="form-control"  value="${m!=null?m.name:'' }">
		                        <small class="help-block">请输入菜单名称</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label" for="demo-text-input">权限标识</label>
		                    <div class="col-md-9">
		                        <input type="text"  name="permission" class="form-control"  value="${m!=null?m.permission:'' }">
		                        <small class="help-block">请输入权限标识</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label" for="demo-text-input">访问地址</label>
		                    <div class="col-md-9">
		                        <input type="text"  name="url" class="form-control"  value="${m!=null?m.url:'' }">
		                        <small class="help-block">请输入访问地址</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label" for="demo-textarea-input">描述信息</label>
		                    <div class="col-md-9">
		                        <textarea name="description" rows="9" class="form-control">${m!=null?m.description:'' }</textarea>
		                        <small class="help-block">请输入菜单的描述信息</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label" for="demo-text-input">是否显示</label>
		
		                    <div class="col-md-4" style="line-height: 30px;">
		                    		<input type="hidden" id="ifShow" name="ifShow" value="1"/>
					                <input  type="checkbox" id="makeIfShow"
					                    <c:if test="${m!=null&&m.ifShow=='1' }">  
					                		checked
					                	</c:if>
					                />
		                    </div>
		                </div>
		                <c:if test="${requestScope.nowBread!='修改菜单'}">
			                <div class="form-group">
			                    <label class="col-md-3 control-label" for="demo-text-input">显示顺序</label>
			                    <div class="col-md-4">
			                        <input type="text" id="sort" name="sort" class="form-control">
			                        <small class="help-block">请输入菜单显示顺序</small>
			                    </div>
			                </div>
		                </c:if>
		                <div class="panel-footer">
		                    <div class="row">
		                        <div class="col-sm-9 col-sm-offset-3">
		                            <button class="btn btn-warning" type="reset">重置</button>
		                            <button class="btn btn-mint" type="submit" >保存</button>
		                        </div>
		                    </div>
		                </div>
		            </form>
		        </div>
		    </div>
	</div>
	<script>
		function saveOrUpdate(){
			var opreate=$("#opreate").val();//进行的操作
			if(opreate!="修改菜单"){
				var sort=$("#sort").val();//显示顺序
				var parentId=$("#parentId").val();//父级菜单id
				//新增菜单id为     父级菜单id拼接显示顺序
				$("#id").val(parentId+""+sort);	
			}
			
			if($("#makeIfShow").prop("checked")!=true){
				$("#ifShow").val("0");//是否显示
			}
			
			if($("#parentId").val()=="0"){
				$("#isparent").val("1");
			}else{
				$("#isparent").val("0");
			}
			var data = common_ajax.ajaxFunc("/admin/menu/saveOrUpdate", $('#editForm').serialize(), "json", null);
			if(data.success){
				pointLion.alertMsg("保存成功!" , "success" , "small" , function(){
					doPjax(ctx+'/admin/menu/getListPage');//跳转到列表页
				});
			}
		}
		//选择一个父级菜单
		var selectedNode={};
		function selectOneMenu(){
			layer.open({
				  type: 2,
				  title: false, //不显示标题栏
				  area: ['370px', '550px'],
				  shade: 0.8,
				  id: 'selectOneMenu', //设定一个id，防止重复弹出
				  resize: false,
				  closeBtn: false,
				  isOutAnim : false , 
				  btn: ['确定', '取消'], 
				  btnAlign: 'c',
				  content: ctx+'/admin/menu/getSelectOneMenuPage',
				  success: function(layero){
					  
				  },
				  yes: function(){
					  	var thisId = $("#id").val();//主键
						if(thisId==selectedNode.id){
							 layer.closeAll();
							 pointLion.alertMsg("您不能选择自己为父级节点!" , "warning" , "small" , null);
							 return;
						}
						$("#parent_name").val(selectedNode.name);//所选单位名称
						$("#parentId").val(selectedNode.id);//所选单位id
					  	layer.closeAll();
				  }
				});
		}
		function setOneMenuNode(node){
			selectedNode = node;
		}
		
		
		$(document).ready(function() {
			new Switchery(document.getElementById('makeIfShow'));//制做开关按钮
		    $('#editForm').bootstrapValidator({
		            fields: {
		            	"name": {
		                    validators: {
		                        notEmpty: {
		                            message: '*菜单名称不能为空'
		                        },
		                        stringLength: {/*长度提示*/
		                            max: 25,
		                            message: '*菜单名称长度必须小于25'
		                        }
		                    }
		                },
		                "sort": {
		                    validators: {
		                    	lessThan: {
		        					inclusive:true,
		        					value: 99,
		        					message: '*请输入小于99的数字'
		        				}
		                    }
		                },
		                "url": {
		                    validators: {
		                    	stringLength: {
		                            max: 100,
		                            message: '*访问地址长度小于100'
		                        }
		                    }
		                },
		                "description": {
		                    validators: {
		                    	stringLength: {
		                            max: 100,
		                            message: '*详细信息长度小于100'
		                        }
		                    }
		                },
		                "permission": {
		                    validators: {
		                    	stringLength: {
		                            max: 50,
		                            message: '*权限标识长度须小于50'
		                        }
		                    }
		                }
		            }
		        }).on("success.form.bv", function (e) {
		        	saveOrUpdate();
		            return false;//阻止表单跳转
		        });
		});
	</script>
</div>
</body>
</html>